#ifndef TISSERIALPORT_H
#define TISSERIALPORT_H

#include <QObject>
#include "qextserialport.h"
#include <QTimer>
#include <QMap>

#include "log.h"

//延时，TIME_OUT是串口读写的延时
#define TIME_OUT 10
//读取定时器计时间隔,200ms，读取定时器是我们读取串口缓存的延时
#define TIMER_INTERVAL 50


/*
*BAUD110                110         110
*BAUD300                300         300
*BAUD600                600         600
*BAUD1200              1200        1200
*BAUD2400              2400        2400
*BAUD4800              4800        4800
*BAUD9600              9600        9600
BAUD14400            14400        9600
*BAUD19200            19200       19200
*BAUD38400            38400       38400
BAUD56000            56000       38400
*BAUD57600            57600       57600
*BAUD115200          115200      115200
BAUD128000          128000      115200
*/

// extern  QMap<long, BaudRateType> bt;
// bt.insert(110, BAUD110);

class TisSerialPort : public QObject
{
    Q_OBJECT
    LOG4QT_DECLARE_QCLASS_LOGGER

public:
    explicit TisSerialPort(QObject *parent = 0);

    typedef QextSerialBase::QueryMode QueryMode;
    bool    OpenPort(int nPort, ulong dwBaudRate, QueryMode mode = QextSerialBase::Polling);
    bool    OpenPort(/*const QString & name*/QString name, ulong dwBaudRate, QueryMode mode = QextSerialBase::Polling);
    void    ClosePort();
    qint64  Send(const char *data, qint64 len);
    qint64  Send(const char *data);
    qint64  Send(const QByteArray &data);

private:
    QextSerialPort *myCom;                            //ivan com类
    QTimer *timer;

    unsigned int timerdly;

    QMap<long, BaudRateType> m_baudRate;

signals:
    void dataArrive(char *data, qint64 len);

public slots:
    void readMyCom();

};

#endif // TISSERIALPORT_H
